<?php require_once 'include/head.php';?>
<!--h_r start-->
    <div class="h_r wd95 mA">
		<ul>
        	<li class="clearfix">
                <span class="fl wd35 texR">
                    姓名：　
                </span>
                <font class="a"><?php echo $user['username'];?></font>
                <input class="disB name" id="username" type="hidden"value="<?php echo $user['username'];?>" />
            </li>
            <li class="clearfix">
                <span class="fl wd35 texR">
                    余额：　
                </span>
                <span class="fl">
                    <font class="a"><?php echo $user['balance'];?></font>
                    <input class="disB name" readonly="readonly" id="balance" type="hidden"value="<?php echo $user['balance'];?>" />
                </span>
            </li>
             <li class="clearfix">
            	<div class="clearfix">
                    <span class="fl wd35 texR">
                        提现金额：　
                    </span>
                    <input class="disB name" id="money" onblur="jisuan()" type="text" placeholder="" />
                </div>
            </li>
            <li class="clearfix">
            	<div class="clearfix">
                    <span class="fl wd35 texR">
                        实际到账金额：　
                    </span>
                    <input class="disB name"readonly="readonly" id="kebalance"  type="text" placeholder="" />
                    <span >税收：￥<font class="red"  id="tax"></font> 管理费￥<font class="red" id="feiyong"></font>提现将扣税，税点8%；管理费2%</span>
                </div>
            </li>
             
            <li class="clearfix">
            	<div class="clearfix">
                    <span class="fl wd35 texR">
                        二级密码：　
                    </span>
                    <input class="disB name" id="password" type="password" placeholder="" />
                </div>
               
                <input class="disB btn cfff font14" onClick="check();" id="txbtn" type="button" value="申请提现" >
            </li>
        </ul>
    </div>
<!--h_r end-->
</body>
<script type="text/javascript">
	function check() {
		
	   var password = document.getElementById("password").value;
           var username = document.getElementById("username").value;
           var money = document.getElementById("money").value;
           money=parseFloat(money);
           var balance=document.getElementById("balance").value;
            balance=parseFloat(balance);
	   var data = {password:password,username:username};
	   var bool = true;

	   
           if(isNaN(money)){
               money=0;
           }
               if(password ==  null ||password == ''){
                    $.alert({
                            title: '提示',
                            content:'密码不能为空',
                            confirm: function(){
                            }
                    });
                    return false;
               }
                if(money >balance){
                        $.alert({
                                     title: '提示',
                                     content:'余额不足',
                                     confirm: function(){
                                     }
                             });
                }
                if( money<0  ){
                        $.alert({
                                     title: '提示',
                                     content:'余额不能是负数',
                                     confirm: function(){
                                     }
                             });
                }
		  
           if( money ==  null ||money == '' || money ==0) {
		   $.alert({
			    title: '提示',
			    content:'提现金额不能为空',
			    confirm: function(){
			    }
			});
	        return false;
	   }
           
	   $.ajax({
			url:"/wap/cash/check_password",
			async: false,
			type:"post",
			data: data,
			dataType: 'json',
			success:function(data) {
				bool = data;
			}	
		});
		if(!bool) {
		   	$.alert({
			    title: '提示',
			    content:'密码错误',
			    confirm: function(){
			    }
			});
			 return false;	
		}
			$("#txbtn").attr("disabled", "disabled"); //使按钮不能被点击 
			$("#txbtn").attr("value", "提交中"); //更改按钮上的文字 
            var post_cash={password:password,money:money}; 
            $.ajax({
			url:"/wap/cash/add",
			async: false,
			type:"post",
			data: post_cash,
			dataType: 'json',
			success:function(data) {
				if(data.success){
                                   window.location.href='/wap/cash';
                                }else{
                                    $.alert({
                                        title: '提示',
                                        content:data.msg,
                                        confirm: function(){
											$("#txbtn").removeAttr("disabled"); //使按钮能够被点击 
											$("#txbtn").attr("value", "申请提现"); //更改按钮上的文字 
                                        }
                                    });
                                        return false;
                                }
			}	
		});
	   return true;
	}
        
        function jisuan(){
            var money = parseFloat(document.getElementById("money").value);
            
            var balance = parseFloat(document.getElementById("balance").value);
            
            if(isNaN(money)){
                money=0;
            }
            var tax=0;
            tax=money*0.08;
            var feiyong =0;
            feiyong=money*0.02;
            var kebalance=parseFloat(money)-(parseFloat(tax)+parseFloat(feiyong));
            if(money ==0){
                $.alert({
                    title: '提示',
                    content:'金额不能为0',
                    confirm: function(){
                    }
                });
                 return false;
            }
            if( money >balance ){
                    $.alert({
                                 title: '提示',
                                 content:'余额不足',
                                 confirm: function(){
                                 }
                         });
            }
            if( money<0  ){
                    $.alert({
                                 title: '提示',
                                 content:'余额不能是负数',
                                 confirm: function(){
                                 }
                         });
            }
		  
            
           $("#tax").html(tax);
           $("#feiyong").html(feiyong);
           $("#kebalance").val(kebalance); 
        }
</script>		
</html>